home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / games / 2a / applicat.ion / drdfnt.c < prev    next >
C/C++ Source or Header  |  1985-05-29  |  3KB  |  171 lines

  1. /* DRDFNT.C: convert 8-bit Atari fonts to DEGAS format
  2.  *
  3.  * link gems,DRDFNT,osbind,gemlib
  4.  *
  5.  * Dr.Download BBS  614-587-3774
  6.  */
  7.  
  8. #include <osbind.h>
  9.  
  10. #define HI_RES       2
  11. #define MED_RES    1
  12. #define LO_RES     0
  13. #define PATHLEN    64
  14.  
  15. #define CLR_SCREEN "\033E"
  16. #define INV_VIDEO  "\033p"
  17. #define NOR_VIDEO  "\033q"
  18. #define W_ON_B     "\033b0\033c3"   /* 0 white  1 red  2 green  3 black */
  19. #define B_ON_W       "\033b3\033c0"
  20. #define CR         "\r\n"
  21. #define WAIT       { }
  22.                         
  23. char buf[2050],path[67];
  24.  
  25. main()
  26. {
  27.     do {
  28.         setup();
  29.         do {
  30.             Cconws("\r\nEnter pathname for 8-bit font: ");
  31.             enter_path();
  32.         } while (read_path());
  33.         setup();  
  34.         do {
  35.             Cconws("\r\nEnter pathname for DEGAS font: ");
  36.             enter_path();
  37.         } while (write_path());
  38.         setup();
  39.         Cconws("\r\nConvert another font? [y/n]: ");
  40.     } while (yesno());
  41.     goodbye();
  42. }
  43.  
  44. /* SETUP: configure screen
  45.  */
  46. int setup()
  47. {
  48.     if (Getrez() == HI_RES) 
  49.         Cconws(W_ON_B);
  50.     else 
  51.         Cconws(B_ON_W);
  52.     Cconws(CLR_SCREEN);
  53.     Cconws(INV_VIDEO);
  54.     Cconws(" DRDFNT.PRG: convert 8-bit fonts to DEGAS format \n");
  55.     Cconws(NOR_VIDEO);
  56.     Cursconf(1,0);       /* cursor: 0 hide  1 show  2 blink  3 no blink */
  57.     Cursconf(3,0);
  58.     return(0);
  59. }
  60.  
  61. /* ENTER_PATH: configure path from keyboard entry
  62.  */
  63. int enter_path()
  64. {
  65.     char *p = path;
  66.     
  67.     path[0] = PATHLEN;
  68.     Cconrs(path);
  69.     Cconws(CR);
  70.     if (path[3] == ':') 
  71.         while (*p++ = *(p+2));
  72.     else {
  73.         path[0] = (Dgetdrv()+65);
  74.         path[1] = ':'; 
  75.     }
  76.     return(0);
  77. }
  78.  
  79. /* READ_PATH: open 8-bit font file; copy each byte twice into the buffer
  80.  */
  81. int read_path()
  82. {
  83.     int handle;
  84.     char *b = buf;
  85.  
  86.     if ((handle = Fopen(path,0)) < 0) {
  87.         Cconws("file open error...");
  88.         Cconws(CR);
  89.         return(1);
  90.         }
  91.     else {
  92.         while (Fread(handle,(long)1,b)) {
  93.             *(b+1) = *b; 
  94.             b+=2;
  95.         }
  96.         Fclose(handle);
  97.         shuffle();
  98.         buf[2048] = 0;
  99.         buf[2049] = 1;      /* enable half-sizes */
  100.     }
  101.     return(0);
  102. }
  103.  
  104. /* SHUFFLE: put letters in ASCII order
  105.  */
  106. int shuffle()
  107. {
  108.     char *row1 = buf,
  109.          *row2 = buf + 512,
  110.          *row3 = buf + 1024;
  111.     int i;
  112.  
  113.     for (i = 0; i < 512; i++) {
  114.         buf[2050] = *(row3+i);
  115.          *(row3+i) = *(row2+i);
  116.         *(row2+i) = *(row1+i);
  117.         *(row1+i) = buf[2050];
  118.     }
  119.     return(0);
  120.  
  121. /* WRITE_PATH: create DEGAS font file; write buffer
  122.  */
  123. int write_path()
  124. {
  125.     long handle,len = 2050;
  126.  
  127.     handle = Fcreate(path,(short)0);
  128.     if (handle >= 0) {    
  129.         Fwrite((short)handle,len,&buf);
  130.         Fclose((short)handle);
  131.     }
  132.     return(0);
  133. }
  134.  
  135. /* YESNO: branch on keyboard entry
  136.  */
  137. int yesno()
  138. {
  139.     int reply;
  140.  
  141.     reply = Bconin(2);
  142.     if ((reply == 89) || (reply == 121))
  143.         return(1);
  144.     else
  145.         return(0);
  146. }
  147.  
  148. /* GOODBYE: clean up & leave
  149.  */
  150. int goodbye()
  151. {
  152.     Cconws(CLR_SCREEN);
  153.     Cconws(INV_VIDEO);
  154.     Cconws(" Dr.Download BBS  614-587-3774 ");
  155.     Cconws(NOR_VIDEO);
  156.     Cconws("\r\n\nPress a key to leave: ");
  157.     wait_key();
  158.     Cconws(CR);
  159.     exit(0);
  160. }
  161.  
  162. /* WAIT_KEY: wait for keyboard entry
  163.  */
  164. int wait_key()
  165. {
  166.     while (!Bconstat(2)) WAIT;
  167.     Bconin(2);
  168.     return(0);
  169. }
  170. ccccccccccccccccccccccccccccc